#include<bits/stdc++.h>

using namespace std;

using i64 = long long;
using u64 = unsigned long long;

struct Ga {
    string left, right;

    Ga(string left, string right) {
        this->left = left;
        this->right = right;
    }
} g[7] = {Ga("S", "E"),
          Ga("E", "E+T"),
          Ga("E", "T"),
          Ga("T", "T*F"),
          Ga("T", "F"),
          Ga("F", "(E)"),
          Ga("F", "i")};
/*
        S->E   r0 //拓广文法
        E->E+T  r1
        E->T  r2
        T->T*F  r3
        T->F  r4
        F->(E)  r5
        F->i  r6
 */                 //      (          )            i        +         *            #          E         F        T
string table[][9] = {"s4", "eor", "s5", "eor", "eor", "eor", "1", "2", "3",
                     "eor", "eor", "eor", "s6", "eor", "acc", "eor", "eor", "eor",
                     "eor", "r2", "eor", "r2", "s7", "r2", "eor", "eor", "eor",
                     "eor", "r4", "eor", "r4", "r4", "r4", "eor", "eor", "eor",
                     "s4", "eor", "s5", "eor", "eor", "eor", "8", "2", "3",
                     "eor", "r6", "eor", "r6", "r6", "r6", "eor", "eor", "eor",
                     "s4", "eor", "s5", "eor", "eor", "eor", "eor", "9", "3",
                     "s4", "eor", "s5", "eor", "eor", "eor", "eor", "eor", "10",
                     "eor", "s11", "eor", "s6", "eor", "eor", "eor", "eor", "eor",
                     "eor", "r1", "eor", "r1", "s7", "r1", "eor", "eor", "eor",
                     "eor", "r3", "eor", "r3", "r3", "r3", "eor", "eor", "eor",
                     "eor", "r5", "eor", "r5", "r5", "r5", "eor", "eor", "eor",
};
string s;
int cnt_1 = 0;

void output(const vector <string> &a, int x) {

    cout << ++cnt_1 << "\t";

    vector <string> c;

    for (int i = 0; i < a.size(); i++) {
        if ( isdigit(a[i][0])) {
            cout << a[i];
        } else {
            c.push_back(a[i]);
        }
    }

    cout << "\t\t" << "#";
    for (int i = 0; i < c.size(); i++) {
        cout << c[i];
    }
    cout << "\t\t";
    for (int i = x; i < s.size(); i++) {
        cout << s[i];
    }
    cout << " ";

}

int main() {

    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    //freopen("input.in", "r", stdin);
    unordered_map<char, int> p;
    p['('] = 0, p[')'] = 1, p['i'] = 2;
    p['+'] = 3, p['*'] = 4, p['#'] = 5;
    p['E'] = 6, p['T'] = 7, p['F'] = 8;

    cin >> s;

    vector <string> st;
    st.push_back("0");

    int i = 0;
    while (true) {
        string t = st.back();

        string y = table[stoi(t)][p[s[i]]];
        if ( y[0] == 's' ) {
            output(st, i);
            y[0] = toupper(y[0]);
            cout << "\t\t" << y << "\n";

            st.push_back(s.substr(i, 1));//先压符号
            st.push_back(y.substr(1));//在压状态
            i++;

        } else if ( y[0] == 'r' ) {
            output(st, i);
            int cnt = 0;
            Ga g1 = g[stoi(y.substr(1))];
            while (cnt < 2 * g1.right.size()) {//弹出 2*right.size()
                st.pop_back();
                cnt++;
            }
            string c1 = g1.left;
            string y1 = table[stoi(st.back())][p[c1[0]]];//goto表
            st.push_back(c1);//先压符号 压入左部
            st.push_back(y1);//在压状态

            cout << "\t\t" << y << "\t" << y1 << "\n";

        } else if ( y == "acc" ) {
            output(st, i);
            cout << "\t\t" << "acc" << "\n";
            break;
        } else {
            output(st, i);
            cout << "\t\t" << "error" << "\n";
            break;
        }
    }
    return 0;
}
/**************************************************************
    Problem: 4045
    User: 2701220528
    Language: C++
    Result: 正确
    Time:4 ms
    Memory:2400 kb
    Judger:judge.aliyun2
****************************************************************/